package net.xdclass.compoent.impl;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.compoent.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MailServiceImpl  implements MailService {

    /**
     * Spring BOOT  提供的邮箱发送
     */
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.from}")
    private String from;

    /**
     * 发送邮件
     * @param to
     * @param subject
     * @param content
     */
    @Override
    public void sendMail(String to, String subject, String content) {
        //创建邮件对象
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();

        //配置发送人
        simpleMailMessage.setFrom(from);
        //配置收件人
        simpleMailMessage.setTo(to);
        //配置主题
        simpleMailMessage.setSubject(subject);
        //邮件内容
        simpleMailMessage.setText(content);
        //发送
        javaMailSender.send(simpleMailMessage);
        log.info("发送邮件的内容：{}"+simpleMailMessage.toString());
    }
}
